<?php

namespace App\Http\Controllers\User;

use App\Http\Controllers\BaseController;
use App\Models\Course;

class CourseController extends BaseController
{
    public function index()
    {
        $data = Course::query()
            ->selectRaw('*,(select sum(view_count) from course_browses where course_id=courses.id) as view_count')
            ->where('status',1)
            ->where('user_id',auth('api')->id())
            ->withCount('chapter')
            ->with('auth:user_id,name')
            ->orderBy('sort')
            ->orderByDesc('id')
            ->simplePaginate(10);

        return $this->success($data);
    }
}
